package com.ruoyi.system.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.PageInfo;
import com.ruoyi.system.utils.MyPageUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.db.basic.BasicCompanies;
import com.ruoyi.system.service.IBasicCompaniesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司管理模块Controller
 * 
 * @author ruoyi
 * @date 2023-07-25
 */
@RestController
@RequestMapping("/basic/companies")
public class BasicCompaniesController extends BaseController
{
    @Autowired
    private IBasicCompaniesService basicCompaniesService;

    /**
     * 查询公司管理模块列表
     */
    @PreAuthorize("@ss.hasPermi('basic:companies:list')")
    @GetMapping("/list")
    public PageInfo<BasicCompanies> list(BasicCompanies basicCompanies)
    {
      //  startPage();
        List<BasicCompanies> list = basicCompaniesService.selectBasicCompaniesList(basicCompanies);
        return MyPageUtils.startPage(list);
    }

    /**
     * 导出公司管理模块列表
     */
    @PreAuthorize("@ss.hasPermi('basic:companies:export')")
    @Log(title = "公司管理模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicCompanies basicCompanies)
    {
        List<BasicCompanies> list = basicCompaniesService.selectBasicCompaniesList(basicCompanies);
        ExcelUtil<BasicCompanies> util = new ExcelUtil<BasicCompanies>(BasicCompanies.class);
        util.exportExcel(response, list, "公司管理模块数据");
    }

    /**
     * 获取公司管理模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:companies:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return success(basicCompaniesService.selectBasicCompaniesByCompanyId(companyId));
    }

    /**
     * 新增公司管理模块
     */
    @PreAuthorize("@ss.hasPermi('basic:companies:add')")
    @Log(title = "公司管理模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicCompanies basicCompanies)
    {
        return toAjax(basicCompaniesService.insertBasicCompanies(basicCompanies));
    }

    /**
     * 修改公司管理模块
     */
    @PreAuthorize("@ss.hasPermi('basic:companies:edit')")
    @Log(title = "公司管理模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicCompanies basicCompanies)
    {
        return toAjax(basicCompaniesService.updateBasicCompanies(basicCompanies));
    }

    /**
     * 删除公司管理模块
     */
    @PreAuthorize("@ss.hasPermi('basic:companies:remove')")
    @Log(title = "公司管理模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(basicCompaniesService.deleteBasicCompaniesByCompanyIds(companyIds));
    }
}
